package de.bbl.android.classes;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import android.graphics.Bitmap;

import de.bbl.android.tools.Tools;

public class RssItem {
	private String title;
	private String description;
	private String link;
	private String guid;
	private String pubDateStr;
	private String[] imagePath;
	private Date pubDate;
	private Bitmap firstBitmap;
	private String shortDateString;
	
	public RssItem(String t, String d, String l, String g, String p) {
		title = t;
		description = d;
		link = l;
		guid = g;
		pubDateStr = p;
		shortDateString = p;
		setPubDate(p);
		imagePath = null;
		setFirstBitmap(null);
	}
	
	public String getTitle() {
		return title;
	}
	
	public String getDescription(){
		return description;
	}
	
	public String getLink() {
		return link;
	}
	
	public void setImagePath(String[] imageP) {
		imagePath = imageP;
	}
	
	public String[] getImagePath() {
		return imagePath;
	}
	
	public String getDate() {
		SimpleDateFormat parserSDF = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
		Date tempDate = null;
		String retval = "";
		try {
			tempDate = parserSDF.parse(pubDateStr.toString());
			parserSDF = new SimpleDateFormat("dd.MM.yyyy");
			parserSDF.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
			retval = parserSDF.format(tempDate);
		} catch (Exception e) {
        	Tools.AppendToErrorFile(e.getMessage());
            // e.printStackTrace();
		}
		return retval;
	}
	
	public Date getPubDate() {
		return pubDate;
	}
	
	private void setPubDate(String p) {
		SimpleDateFormat parserSDF = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
		Date tempDate = null;
		try {
			tempDate = parserSDF.parse(p);
			parserSDF = new SimpleDateFormat("dd.MM.yyyy");
			parserSDF.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
			tempDate = parserSDF.parse(parserSDF.format(tempDate));
			shortDateString = parserSDF.format(tempDate);
		} catch (Exception e) {
        	Tools.AppendToErrorFile(e.getMessage());
            // e.printStackTrace();
		}
		pubDate = tempDate;
	}
	
	@Override
	public String toString() {
		return "Title: " + title + " desc: " + description + " link: " + link + " guid: " + guid + " pubdate: " + pubDateStr;
	}

	public Bitmap getFirstBitmap() {
		return firstBitmap;
	}

	public void setFirstBitmap(Bitmap bitmap) {
		this.firstBitmap = bitmap;
	}

	public String getShortDateString() {
		return shortDateString;
	}

	public void setShortDateString(String shortDateString) {
		this.shortDateString = shortDateString;
	}
	
}
